/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package cl.zeke.pizzastore.negocio.entities;

import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

/**
 *
 * @author taller
 */
@Entity
@Table(name = "PIZZA_INGREDIENTE")
@NamedQueries({
    @NamedQuery(name = "PizzaIngrediente.findAll", query = "SELECT p FROM PizzaIngrediente p"),
    @NamedQuery(name = "PizzaIngrediente.findByIdPizza", query = "SELECT p FROM PizzaIngrediente p WHERE p.pizzaIngredientePK.idPizza = :idPizza"),
    @NamedQuery(name = "PizzaIngrediente.findByIdIngrediente", query = "SELECT p FROM PizzaIngrediente p WHERE p.pizzaIngredientePK.idIngrediente = :idIngrediente"),
    @NamedQuery(name = "PizzaIngrediente.findByCantidad", query = "SELECT p FROM PizzaIngrediente p WHERE p.cantidad = :cantidad")})
public class PizzaIngrediente implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected PizzaIngredientePK pizzaIngredientePK;
    @Basic(optional = false)
    @Column(name = "CANTIDAD")
    private int cantidad;
    @JoinColumn(name = "ID_INGREDIENTE", referencedColumnName = "ID_INGREDIENTE", insertable = false, updatable = false)
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private Ingrediente ingrediente;
    @JoinColumn(name = "ID_PIZZA", referencedColumnName = "ID_PIZZA", insertable = false, updatable = false)
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private Pizza pizza;

    public PizzaIngrediente() {
    }

    public PizzaIngrediente(PizzaIngredientePK pizzaIngredientePK) {
        this.pizzaIngredientePK = pizzaIngredientePK;
    }

    public PizzaIngrediente(PizzaIngredientePK pizzaIngredientePK, int cantidad) {
        this.pizzaIngredientePK = pizzaIngredientePK;
        this.cantidad = cantidad;
    }

    public PizzaIngrediente(long idPizza, long idIngrediente) {
        this.pizzaIngredientePK = new PizzaIngredientePK(idPizza, idIngrediente);
    }

    public PizzaIngredientePK getPizzaIngredientePK() {
        return pizzaIngredientePK;
    }

    public void setPizzaIngredientePK(PizzaIngredientePK pizzaIngredientePK) {
        this.pizzaIngredientePK = pizzaIngredientePK;
    }

    public int getCantidad() {
        return cantidad;
    }

    public void setCantidad(int cantidad) {
        this.cantidad = cantidad;
    }

    public Ingrediente getIngrediente() {
        return ingrediente;
    }

    public void setIngrediente(Ingrediente ingrediente) {
        this.ingrediente = ingrediente;
    }

    public Pizza getPizza() {
        return pizza;
    }

    public void setPizza(Pizza pizza) {
        this.pizza = pizza;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (pizzaIngredientePK != null ? pizzaIngredientePK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof PizzaIngrediente)) {
            return false;
        }
        PizzaIngrediente other = (PizzaIngrediente) object;
        if ((this.pizzaIngredientePK == null && other.pizzaIngredientePK != null) || (this.pizzaIngredientePK != null && !this.pizzaIngredientePK.equals(other.pizzaIngredientePK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "cl.zeke.pizzastore.negocio.entities.PizzaIngrediente[ pizzaIngredientePK=" + pizzaIngredientePK + " ]";
    }
    
}
